import { Map } from "immutable";

import * as actionTypes from "./constants";

// 2. 转为ImMutableJS对象
const defaultState = Map({
  topBanners: [],            //轮播
  hotRecommends: [],        //热门推荐
  newAlbums: [],           //新碟上架
  upRanking: {},          //飙升榜
  newRanking: {},        //新歌榜
  originRanking: {},    //原创榜
  settleSings: []      //入驻歌手
})


// 1.对象的浅拷贝存在的问题：如果对象过于庞大，拷贝会带来性能的问题以及内存浪费；
function reducer(state = defaultState, action) {
  switch (action.type) {
    case actionTypes.CHANGE_TOP_BANNERS:
      return state.set("topBanners", action.topBanners);
    case actionTypes.CHANGE_HOT_RECOMMENDS:
      return state.set("hotRecommends", action.hotRecommends);
    case actionTypes.CHNAGE_NEW_ALBUMS:
      return state.set("newAlbums", action.newAlbums);

    case actionTypes.CHNAGE_UP_RANKING:
      return state.set("upRanking", action.upRanking);
    case actionTypes.CHNAGE_NEW_RANKING:
      return state.set("newRanking", action.newRanking);
    case actionTypes.CHNAGE_ORIGIN_RANKING:
      return state.set("originRanking", action.originRanking);
    
    case actionTypes.CHANGE_SETTLE_SINGER:
      return state.set("settleSings", action.settleSings);
    default:
      return state;
  }
}

export default reducer;